<template>
<view>
	<view style="display: flex;background-color: white;align-items: center;padding:5px 10px;justify-content: space-between;">
		<view @click="tel(userinfo.tel)" style="display: flex;align-items: center;">
			<u-avatar :src="userinfo.avatar" size="35"></u-avatar>
			<p style="margin-left: 5px;color: #868686;display: flex;align-items: center;">{{userinfo.nickname}}<u-icon v-if="userinfo.vip>new Date().getTime()" name="/static/other/vip.png" style="margin-left: 3px;" size="18" /></p>
		</view>
			<p style="display: flex;align-items: center;font-size: 13px;" @click="report(data._id,data.title)">举报</p>
		</view>
		<view style="background-color: white;padding:5px 10px 10px 10px;">
			<u-search placeholder="请输入文件名" @blur="search" :showAction="false"></u-search>
		</view>
		<view style="height: 1px;background-color: #eeeeee;" />
		<view v-if="data.content!=null&&data.content.length!=0" style="padding: 15px;background-color: white;">
			<view style="background-color: #fff6e4;color: #7b7458;padding: 7px;border-radius: 7px;font-size: 14px;">
				<rich-text selectable :nodes="data.content"></rich-text>
			</view>
		</view>
		<unicloud-db style="margin-top: 10px;" field="password_mode,down,ip,time,title,type,up,password,url,weight,last_time,top,duration,size,icon" :page-current="page" ref="udb" v-slot:default="{data, pagination, loading, error,hasMore, options}"
				collection="item" orderby="top desc,last_time desc,weight asc,time desc" :where="where">
				<view v-if="hasMore||data.length>0" v-for="(item,index ) in data" :key="index" @click="share(item._id)">
					<item_file v-if="item.type=='file'" :item="item">
					</item_file>
					<item_img v-if="item.type=='img'" :item="item">
					</item_img>
					<item_doc v-if="item.type=='document'" :item="item">
					</item_doc>
					<item_apk v-if="item.type=='apk'" :item="item">
					</item_apk>
					<item_bt v-if="item.type=='bt'" :item="item">
					</item_bt>
					<item_video v-if="item.type=='video'" :item="item">
					</item_video>
					<item_other v-if="item.type=='other'" :item="item">
					</item_other>
				</view>
				<u-loadmore v-if="loading" loadingText="拼命加载中" status="loading" />
				<view v-if="data.length==0&&!loading&&!hasMore" style="text-align: center;margin-top: 20px;">
					<u-empty mode="data" text="没有内容~">
					</u-empty>
				</view>
			</unicloud-db>
	<websitenav></websitenav>
</view>
</template>

<script>
	const db = uniCloud.database();
	export default {
		props: {
			data: {
				type: Object,
				default (data) {
					return {}
				}
			},
			page: {
				type: Number,
				default:1
			}
		},
		name: "file_jingdian",
		data() {
			return {
				where:"up=='"+this.data._id+"'",
			userinfo:{
				title:null,
				tel:null,
				avatar:null
			}
			};
		},
		methods:{
			tel(tel){
				if(tel==null){
					return null
				}
				uni.showModal({
					title: '联系方式',
					content: tel
				});
			},
			report(id){
				uni.navigateTo({
					url: '../feedback/feedback?id='+id+'&type=file'
				});
			},
			gsduration(d){
				var a=d.toFixed(0)
				var s,m;
				s=(a%60)<10?'0'+(a%60):(a%60)
				m=(a/60).toFixed(0)
				if(a<60){
					return '00:'+s
				}else if(60<=a){
					if(m<=9){
						return '0'+m+':'+s
					}else{
						return m+':'+s
					}
				}
			},
			search(e){
				this.where = "up=='" + this.data._id + "'&&/" + e + "/.test(title)"
				this.$nextTick(() => {
					this.$refs.udb.loadData({
						clear: true
					})
				})
			},
			async getuserinfo(id){
				const res=await db.collection("uni-id-users").where({_id:id}).field("nickname,avatar,tel,vip").get()
					this.userinfo=res.result.data[0]
			},
			share(id) {
				uni.navigateTo({
					url: '../share/share?id=' + id
				});
			}
		},
		mounted() {
			this.getuserinfo(this.data.user_id)
		}
	}
</script>

<style lang="less">
	page {
		background-color: white;
	}
</style>
